#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "highdata.h"

#define  VPE_MODE 1

#if(0 != VPE_MODE)
#include <math.h>
#include <stdlib.h>

volatile int32_t virtual_pe = 0;
int16_t virtual_pe_b = 100;
int16_t virtual_pe_i = 300;

#if(1 == VPE_MODE)
int16_t sine_wave(int16_t hz, int16_t k) {
    static int16_t idx = 0;
    float radian = 0;
    if(idx < hz ) {
        idx++;
    }else {
        idx = 0;
    }
    radian = (float)idx;
    radian = radian / (float)hz;
    radian = 2 * 3.14 * radian;
    return (int16_t)((float)k * sin(radian));
}
#endif

void virtual_pe_handle(void) {
    static int32_t cnt = 0;
    int32_t pe = 0;
    uint8_t update = 0;
#if(1 == VPE_MODE)
    pe = sine_wave(3000, virtual_pe_i);
    update = 1;
#elif(2 == VPE_MODE)
    if((cnt++)%500 == 0 ) {
        pe = rand()%1000;
        update = 1;
    }
#else    
#endif
    if( update ) {
        virtual_pe = pe + virtual_pe_b;
    }
}

#endif

